package fakedata

import (
	"doctor_api_backend/config"
	"doctor_api_backend/models"
	"fmt"
	"math/rand"
	"time"
)

// 医生信息有系统用户创建，所以医生信息不能随机模拟

func SeedDoctorData() {
	names := []string{"张三", "李四", "王五", "赵六", "钱七", "孙八", "周九", "吴十"}
	genders := []string{"男", "女"}
	departments := []string{"内科", "外科", "妇产科", "儿科", "急诊科"}
	positions := []string{"主任医师", "副主任医师", "主治医师", "住院医师"}

	for i := 0; i < 100; i++ {
		doctor := models.Doctor{
			Name:        names[rand.Intn(len(names))],
			Gender:      genders[rand.Intn(len(genders))],
			DateOfBirth: generateRandomDateForDoctor(),
			Department:  departments[rand.Intn(len(departments))],
			Position:    positions[rand.Intn(len(positions))],
			// 电话要随机生成不重复
			ContactPhone: fmt.Sprintf("138%08d", rand.Intn(99999999)),
			// 邮箱要随机生成不重复
			Email:   fmt.Sprintf("doctor_%d@example.com", i),
			Address: "北京市",
		}

		config.DB.Create(&doctor)
	}

	fmt.Println("100 条假 `医生`数据已成功插入数据库")
}

// 生成随机日期
func generateRandomDateForDoctor() time.Time {
	year := rand.Intn(50) + 1970 // 生成过去 50 年内的日期
	month := time.Month(rand.Intn(12) + 1)
	day := rand.Intn(28) + 1
	return time.Date(year, month, day, 0, 0, 0, 0, time.UTC)
}
